package cn.wsalix.sale.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.anlaser.service.impl.CommonServiceImpl;
import cn.wsalix.sale.entity.SaleMonth;
import cn.wsalix.sale.form.SaleMonthForm;
import cn.wsalix.sale.repository.SaleMonthRepository;
import cn.wsalix.sale.service.SaleMonthService;
import cn.anlaser.utils.SearchFilter;
import cn.anlaser.utils.SearchFilter.Operator;

@Service("saleMonthService")
public class SaleMonthServiceImpl extends
		CommonServiceImpl<SaleMonthForm, SaleMonthRepository, SaleMonth>
		implements SaleMonthService {
	@Autowired
	private SaleMonthRepository salemonthRepository;

	@Override
	public String module() {
		return "/sale/sale_month";
	}

	@Override
	public SaleMonthRepository getRepository() {
		return salemonthRepository;
	}

	@Override
	public Class<SaleMonth> getEntityClazz() {
		return SaleMonth.class;
	}

	@Override
	public Map<String, SearchFilter> buildByForm(SaleMonthForm form) {
		Map<String, Object> searchParams = new HashMap<String, Object>();
		Map<String, SearchFilter> filters = SearchFilter.parse(searchParams);
		if (form.getMonth() != null && !form.getMonth().equals("")) {
			filters.put("month",
					new SearchFilter("month", Operator.EQ, form.getMonth()));
		}
		if (form.getProductId() != null && form.getProductId() != 0) {
			filters.put("productId", new SearchFilter("productId", Operator.EQ,
					form.getProductId()));
		}
		return filters;
	}

}
